﻿package mortal.game.control
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.proxy.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.forging.view.*;
    import mortal.game.view.forging.view.compound.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.palyer.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ForgingController extends Controller
    {
        private var _forgingCache:ForgingCache;
        private var _equipProxy:EquipProxy;
        private var _forgingModule:ForgingModule;
        private var _strengInfo:Object;
        private var _putOnEquip:ItemData;
        private var _currStrengTipData:ItemData;
        private var _hasOperedTipData:Boolean;
        private var _cdData:ICDData;

        public function ForgingController()
        {
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this._forgingCache = cache.forging;
            this._equipProxy = GameProxy.equip;
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._forgingModule == null)
            {
                this._forgingModule = new ForgingModule();
                this._forgingModule.addEventListener(WindowEvent.SHOW, this.onForgingShow);
                this._forgingModule.addEventListener(WindowEvent.CLOSE, this.onForgingClose);
            }
            return this._forgingModule;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.FirstFourStrengthenInfo, this.StrengthenValidateHandler);
            Dispatcher.addEventListener(EventName.GetOffEquip, this.unloadEquipHandler);
            Dispatcher.addEventListener(EventName.OpenForgingPanel, this.openForgingPanelHandler);
            Dispatcher.addEventListener(EventName.AddForgingEquip, this.addForgingEquipHandler);
            Dispatcher.addEventListener(EventName.ForgingAutoTransfer, this.onAutoTransferHandler2);
            Dispatcher.addEventListener(EventName.ForgingOperateByTips, this.onOperateByTips);
            Dispatcher.addEventListener(EventName.EquipTransform, this.equipTransform);
            Dispatcher.addEventListener(EventName.ForgingOpenCompoundPanel, this.openCompoundPanel);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.backPackItemUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.EquipTransferInfoUpdate, this.onTransferSuccHandler);
            return;
        }// end function

        private function onForgingShow(event:Event) : void
        {
            NetDispatcher.addCmdListener(ServerCommand.UpdateForgingEquip, this.updateEquipByType);
            NetDispatcher.addCmdListener(ServerCommand.StrengthenInfoUpdate, this.StrengthenInfoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.EmbedInfoUpdate, this.embedInfoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.GemUpgradeInfoUpdate, this.gemUpgradeHandler);
            NetDispatcher.addCmdListener(ServerCommand.RefreshInfoUpdate, this.refreshInfoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemAdd, this.backPackItemUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemDel, this.backPackItemUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.EquipQualInfoUpdate, this.equipQualInfoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.EquipColorInfoUpdate, this.equipColorInfoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.enableForgingPanel);
            NetDispatcher.addCmdListener(ServerCommand.MoneyUpdate, this.onMoneyUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.ForgingStrengthenFail, this.onStrengthenFailHandler);
            Dispatcher.addEventListener(EventName.EquipStrengthen, this.equipStrengthenHandler);
            Dispatcher.addEventListener(EventName.EmbeGem, this.embedGemHandler);
            Dispatcher.addEventListener(EventName.RemoveGem, this.removeGemHandler);
            Dispatcher.addEventListener(EventName.UpgradeGem, this.upgradeGemHandler);
            Dispatcher.addEventListener(EventName.GemPage, this.gemPageHandler);
            Dispatcher.addEventListener(EventName.EquipRefresh, this.equipRefresh);
            Dispatcher.addEventListener(EventName.EquipRefreshReplace, this.equipRefreshReplace);
            Dispatcher.addEventListener(EventName.EquipQualAdvance, this.equipQualityAdvance);
            Dispatcher.addEventListener(EventName.EquipColorAdvance, this.equipColorAdvance);
            Dispatcher.addEventListener(EventName.ForgingStrengInfoUpdate, this.updateAfterEffectHandler);
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateComBat, this.updateRoleComBat);
            return;
        }// end function

        private function onForgingClose(event:Event) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.StrengthenInfoUpdate, this.StrengthenInfoUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.UpdateForgingEquip, this.updateEquipByType);
            NetDispatcher.removeCmdListener(ServerCommand.EmbedInfoUpdate, this.embedInfoUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.GemUpgradeInfoUpdate, this.gemUpgradeHandler);
            NetDispatcher.removeCmdListener(ServerCommand.RefreshInfoUpdate, this.refreshInfoUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemAdd, this.backPackItemUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemDel, this.backPackItemUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.EquipQualInfoUpdate, this.equipQualInfoUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.EquipColorInfoUpdate, this.equipColorInfoUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.RoleLevelUpdate, this.enableForgingPanel);
            NetDispatcher.removeCmdListener(ServerCommand.MoneyUpdate, this.onMoneyUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.ForgingStrengthenFail, this.onStrengthenFailHandler);
            Dispatcher.removeEventListener(EventName.EquipStrengthen, this.equipStrengthenHandler);
            Dispatcher.removeEventListener(EventName.EmbeGem, this.embedGemHandler);
            Dispatcher.removeEventListener(EventName.RemoveGem, this.removeGemHandler);
            Dispatcher.removeEventListener(EventName.UpgradeGem, this.upgradeGemHandler);
            Dispatcher.removeEventListener(EventName.GemPage, this.gemPageHandler);
            Dispatcher.removeEventListener(EventName.EquipRefresh, this.equipRefresh);
            Dispatcher.removeEventListener(EventName.EquipRefreshReplace, this.equipRefreshReplace);
            Dispatcher.removeEventListener(EventName.EquipQualAdvance, this.equipQualityAdvance);
            Dispatcher.removeEventListener(EventName.EquipColorAdvance, this.equipColorAdvance);
            Dispatcher.removeEventListener(EventName.ForgingStrengInfoUpdate, this.updateAfterEffectHandler);
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateComBat, this.updateRoleComBat);
            return;
        }// end function

        private function addForgingEquipHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as PlayerEquipItem;
            if (this._forgingModule && this._forgingModule.currentPanel)
            {
                this._forgingModule.currentPanel.addForgingEquip(_loc_2);
            }
            return;
        }// end function

        private function equipStrengthenHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = ClientSetting.local.getIsDone(IsDoneType.AutoBuyStrengProp);
            var _loc_4:* = new EOperType(_loc_2.strengType);
            var _loc_5:* = new EPriorityType(0);
            GameProxy.equip.strengthen(_loc_2.uid, _loc_4, _loc_3, _loc_5);
            return;
        }// end function

        private function equipRefresh(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            GameProxy.equip.equipRefresh(_loc_2.equipUid, _loc_2.type, _loc_2.autoBuyRefreshTone, _loc_2.autoBuyLockMaterial, _loc_2.priority, _loc_2.lockDict, _loc_2.expectAttr, _loc_2.expectAttrAll);
            Cache.instance.forging.refreshCallBackFlag = ForgingConst.RefreshFlag_Refresh;
            return;
        }// end function

        private function equipRefreshReplace(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            GameProxy.equip.equipRefreshReplace(_loc_2.equipUid, _loc_2.replaceIndex);
            Cache.instance.forging.refreshCallBackFlag = ForgingConst.RefreshFlag_Replace;
            return;
        }// end function

        private function equipColorAdvance(event:DataEvent) : void
        {
            var _loc_2:* = event.data as String;
            var _loc_3:* = new EOperType(EOperType._EOperTypeSimple);
            var _loc_4:Boolean = false;
            var _loc_5:* = new EPriorityType(EPriorityType._EProiorityTypeBindFirst);
            GameProxy.equip.equipColorAdvance(_loc_2, _loc_3, _loc_4, _loc_5);
            return;
        }// end function

        private function equipQualityAdvance(event:DataEvent) : void
        {
            var _loc_2:* = event.data as String;
            var _loc_3:* = new EOperType(EOperType._EOperTypeSimple);
            var _loc_4:Boolean = false;
            var _loc_5:* = new EPriorityType(EPriorityType._EProiorityTypeBindFirst);
            GameProxy.equip.equipQualityAdvance(_loc_2, _loc_3, _loc_4, _loc_5);
            return;
        }// end function

        private function equipTransform(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2.fromUid;
            var _loc_4:* = _loc_2.toUid;
            var _loc_5:* = _loc_2.fromPosType;
            var _loc_6:* = _loc_2.toPosType;
            GameProxy.equip.equipTransfer(_loc_3, _loc_4, _loc_5, _loc_6);
            return;
        }// end function

        private function StrengthenInfoUpdateHandler(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (param1)
            {
                this._strengInfo = param1;
                _loc_2 = param1.result as int;
                _loc_3 = param1.strengType as int;
                this.updateAfterEffectHandler();
                if (_loc_2 == EStrengthResult._EStrengtheResultFailedAmout || _loc_2 == EStrengthResult._EStrengthResultSuccess)
                {
                    (this._forgingModule.currentPanel as StrengthenPanel).playStrengthenEffect();
                    this.extraOperAfterStrengSucc();
                }
            }
            return;
        }// end function

        private function extraOperAfterStrengSucc() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingStrengTargetUpdate, EquipmentUtil.getStrengTargetLevel()));
            return;
        }// end function

        private function updateAfterEffectHandler(event:DataEvent = null) : void
        {
            var strengResult:int;
            var consumes:Array;
            var playerItem:SPlayerItem;
            var currStrengthenProgress:int;
            var currStrengthenLevel:int;
            var strengthenAmount:int;
            var equipItemData:ItemData;
            var strengPanel:StrengthenPanel;
            var propArr:Array;
            var arr:Array;
            var item:Object;
            var id:uint;
            var e:* = event;
            var currEquip:* = this._forgingModule.equipDisplaySpr.currSelEquip;
            if (this._strengInfo && currEquip && currEquip.itemData && currEquip.itemData.uid == this._strengInfo.resultEquip.uid)
            {
                strengResult = this._strengInfo.result as int;
                consumes = this._strengInfo.consumes as Array;
                playerItem = this._strengInfo.resultEquip as SPlayerItem;
                cache.pack.packRolePackCache.updateSPlayerItem(playerItem);
                equipItemData = cache.pack.packRolePackCache.getItemDataByUid(playerItem.uid);
                if (equipItemData != null)
                {
                    currStrengthenProgress = equipItemData.extInfo.currentStrengthen;
                    currStrengthenLevel = equipItemData.extInfo.strengthen;
                    strengthenAmount = equipItemData.extInfo.strengthenAmount;
                }
                if (currStrengthenProgress == 0)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingPerfectStrenSucc));
                }
                this.displayStrengthenResult(strengResult, currStrengthenLevel);
                cache.forging.updateStrengthenProgress(playerItem.uid, currStrengthenProgress);
                strengPanel = this._forgingModule.currentPanel as StrengthenPanel;
                if (strengResult == EStrengthResult._EStrengtheResultFailedAmout || strengResult == EStrengthResult._EStrengthResultSuccess)
                {
                    if (equipItemData != null)
                    {
                        propArr = this.getStrengInfo2(equipItemData);
                        arr = new Array();
                        var _loc_3:int = 0;
                        var _loc_4:* = propArr;
                        while (_loc_4 in _loc_3)
                        {
                            
                            item = _loc_4[_loc_3];
                            arr.push(item.propStrengValue);
                        }
                        this.displayUpValue(cache.forging.getPerUpValue(arr));
                        strengPanel.updateEquipProp(propArr);
                        strengPanel.updateStrengCombat();
                    }
                    if (currStrengthenLevel == ForgingConst.MaxStrengLevel)
                    {
                        strengPanel.canBeStrengthened = false;
                    }
                }
                if (strengResult == EStrengthResult._EStrengthResultSuccess && currStrengthenLevel >= 1 && currStrengthenProgress == 0)
                {
                    var onTimeOut:* = function () : void
            {
                clearTimeout(id);
                strengPanel.updateProgressBar(0, ForgingConst.TotalStrengProgress);
                return;
            }// end function
            ;
                    strengPanel.updateProgressBar(ForgingConst.TotalStrengProgress, ForgingConst.TotalStrengProgress);
                    id = setTimeout(onTimeOut, 100);
                    strengPanel.addStrengUpEffect();
                    strengPanel.updateBestEquip();
                }
                else
                {
                    strengPanel.updateProgressBar(currStrengthenProgress, ForgingConst.TotalStrengProgress);
                }
                this.updateStrengTipInfo(currEquip.itemData);
            }
            return;
        }// end function

        private function updateStrengTipInfo(param1:ItemData) : void
        {
            if (this._currStrengTipData != null)
            {
                if (this._currStrengTipData.uid == param1.uid)
                {
                    this._hasOperedTipData = true;
                }
            }
            return;
        }// end function

        private function refreshInfoUpdateHandler(param1:Object) : void
        {
            var _loc_2:* = param1.resultEquip;
            var _loc_3:* = param1.consumes;
            cache.pack.packRolePackCache.updateSPlayerItem(_loc_2);
            var _loc_4:* = this._forgingModule.equipDisplaySpr.getEquipById(_loc_2.uid);
            if (_loc_4)
            {
                _loc_4.updateRefreshState();
            }
            return;
        }// end function

        private function equipQualInfoUpdateHandler(param1:Object) : void
        {
            var _loc_2:* = param1.resultEquip;
            var _loc_3:* = param1.consumes;
            cache.pack.packRolePackCache.updateSPlayerItem(_loc_2);
            return;
        }// end function

        private function equipColorInfoUpdateHandler(param1:Object) : void
        {
            var _loc_2:* = param1.resultEquip;
            var _loc_3:* = param1.consumes;
            cache.pack.packRolePackCache.updateSPlayerItem(_loc_2);
            return;
        }// end function

        private function updateGemInfo(param1:int = -1) : void
        {
            var _loc_2:* = this.getGemsByType(0);
            if (param1 >= 0)
            {
                _loc_2.sort(this.sortOnTypeMatch);
            }
            else
            {
                _loc_2.sort(this.sortOnTypeMatch2);
            }
            (this._forgingModule.currentPanel as GemEmbedPanel).updateGemInfo(_loc_2);
            (this._forgingModule.currentPanel as GemEmbedPanel).updateTipsInfo();
            return;
        }// end function

        private function sortOnTypeMatch(param1:ItemData, param2:ItemData) : Number
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_3:* = this._forgingModule.equipDisplaySpr.currSelEquip;
            if (_loc_3 && _loc_3.itemData)
            {
                _loc_4 = _loc_3.itemData.itemInfo.type;
                _loc_5 = EquipJewelMatchConfig.instance.getInfoByType(_loc_4).jeweltype;
            }
            if (param1.itemInfo.type == _loc_5 && param2.itemInfo.type != _loc_5)
            {
                return -1;
            }
            if (param1.itemInfo.type != _loc_5 && param2.itemInfo.type == _loc_5)
            {
                return 1;
            }
            return this.bagItemSort(param1, param2);
        }// end function

        private function sortOnTypeMatch2(param1:ItemData, param2:ItemData) : Number
        {
            var _loc_7:int = 0;
            var _loc_3:* = EquipJewelMatchConfig.instance.getEquipTypeByJewelType(param1.itemInfo.type);
            var _loc_4:* = EquipJewelMatchConfig.instance.getEquipTypeByJewelType(param2.itemInfo.type);
            var _loc_5:Array = [];
            var _loc_6:Array = [];
            for each (_loc_7 in _loc_3)
            {
                
                _loc_5.push(this._forgingModule.equipDisplaySpr.getEquipByType(_loc_7));
            }
            for each (_loc_7 in _loc_4)
            {
                
                _loc_6.push(this._forgingModule.equipDisplaySpr.getEquipByType(_loc_7));
            }
            if (_loc_5.length > 0 && _loc_6.length == 0)
            {
                return -1;
            }
            if (_loc_5.length == 0 && _loc_6.length > 0)
            {
                return 1;
            }
            return this.bagItemSort(param1, param2);
        }// end function

        private function bagItemSort(param1:ItemData, param2:ItemData) : int
        {
            if (param2 == null)
            {
                return -1;
            }
            if (param1 == null)
            {
                return 1;
            }
            if (ItemsUtil.isBind(param1))
            {
                if (ItemsUtil.isBind(param2))
                {
                    if (param1.serverData.itemCode > param2.serverData.itemCode)
                    {
                        return -1;
                    }
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
            else
            {
                if (ItemsUtil.isBind(param2))
                {
                    return 1;
                }
                if (param1.serverData.itemCode > param2.serverData.itemCode)
                {
                    return -1;
                }
                return 1;
            }
        }// end function

        private function embedInfoUpdateHandler(param1:Object) : void
        {
            var _loc_2:SPlayerItem = null;
            var _loc_3:ItemData = null;
            var _loc_4:PlayerEquipItem = null;
            if (param1 != null)
            {
                _loc_2 = param1.resultEquip;
                cache.pack.packRolePackCache.updateSPlayerItem(_loc_2);
                _loc_3 = cache.pack.packRolePackCache.getItemDataByUid(_loc_2.uid);
                _loc_4 = this._forgingModule.equipDisplaySpr.getEquipById(_loc_2.uid);
                if (_loc_4)
                {
                    _loc_4.updateEmbedState();
                    _loc_4.updateGemEmbedInfo();
                }
                if (_loc_3 != null)
                {
                    if (param1.type == 0)
                    {
                        (this._forgingModule.currentPanel as GemEmbedPanel).onEmbedSuccHandler();
                    }
                    else if (param1.type == 1)
                    {
                        (this._forgingModule.currentPanel as GemEmbedPanel).onExciseSuccHandler();
                    }
                }
            }
            this.extraOperAfterEmbed();
            return;
        }// end function

        private function extraOperAfterEmbed() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingGemCombatTargetUpdate, EquipmentUtil.getTotalGemCombatInRole()));
            return;
        }// end function

        private function gemUpgradeHandler(param1:Object) : void
        {
            var _loc_2:* = param1.resultEquip;
            var _loc_3:* = param1.consumes;
            var _loc_4:* = param1.result;
            cache.pack.packRolePackCache.updateSPlayerItem(_loc_2);
            return;
        }// end function

        private function getGemsByType(param1:int) : Array
        {
            var _loc_2:* = cache.pack.backPackCache.getGemByType(param1);
            return _loc_2;
        }// end function

        private function embedGemHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as Array;
            var _loc_3:* = this._forgingModule.equipDisplaySpr.currSelEquip.itemData.uid;
            GameProxy.equip.jewelEmbed(_loc_3, _loc_2);
            return;
        }// end function

        private function removeGemHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as Array;
            var _loc_3:* = this._forgingModule.equipDisplaySpr.currSelEquip.itemData.uid;
            GameProxy.equip.jewelRemove(_loc_3, _loc_2);
            return;
        }// end function

        private function upgradeGemHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data.gemUid;
            var _loc_3:* = event.data.equipUid;
            var _loc_4:* = event.data.upgradeType;
            var _loc_5:* = event.data.holeIndex;
            var _loc_6:* = ClientSetting.local.getIsDone(IsDoneType.AutoBuyGemProp);
            var _loc_7:* = new EOperType(_loc_4);
            GameProxy.equip.jewelUpdate(null, _loc_5, _loc_7, _loc_6, _loc_3);
            return;
        }// end function

        private function StrengthenValidateHandler(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            if (_loc_2 != null)
            {
                cache.forging.updateFirstFourStrengthenData(_loc_2);
            }
            return;
        }// end function

        private function displayStrengthenResult(param1:int, param2:int) : void
        {
            switch(param1)
            {
                case EStrengthResult._EStrengthResultSuccess:
                {
                    MsgManager.showMouseMsg(Language.getString(20387), MsgRollTipsType.msgRollTips2);
                    break;
                }
                case EStrengthResult._EStrengthResultFailedMaterial:
                {
                    MsgManager.showMouseMsg(Language.getString(20388), MsgRollTipsType.msgRollTips3);
                    break;
                }
                case EStrengthResult._EStrengthResultFailedCoin:
                {
                    MsgManager.showMouseMsg(Language.getString(20389), MsgRollTipsType.msgRollTips3);
                    break;
                }
                case EStrengthResult._EStrengthResultFailedGold:
                {
                    MsgManager.showMouseMsg(Language.getString(20390), MsgRollTipsType.msgRollTips3);
                    break;
                }
                case EStrengthResult._EStrengtheResultFailedAmout:
                {
                    MsgManager.showMouseMsg(Language.getString(20391), MsgRollTipsType.msgRollTips2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function updateStrengthenLevel(param1:int) : void
        {
            return;
        }// end function

        private function getStrengthenInfoByLevel(param1:int) : TEquipStrengthen
        {
            var _loc_2:* = EquipStrengthenConfig.instance.getInfoByLevel(param1);
            return _loc_2;
        }// end function

        private function getStrengInfo(param1:ItemData, param2:ItemEquipInfo) : Array
        {
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_3:* = param1.extInfo.currentStrengthen;
            var _loc_4:* = param1.extInfo.strengthen;
            var _loc_5:* = _loc_3 / ForgingConst.TotalStrengProgress;
            if (_loc_4 == 0)
            {
                _loc_6 = 0;
                _loc_7 = cache.forging.getPropAddPercentByLevel((_loc_4 + 1));
            }
            else if (_loc_4 < ForgingConst.MaxStrengLevel)
            {
                _loc_6 = cache.forging.getPropAddPercentByLevel(_loc_4);
                _loc_7 = cache.forging.getPropAddPercentByLevel((_loc_4 + 1));
            }
            else
            {
                _loc_6 = cache.forging.getPropAddPercentByLevel(_loc_4);
                _loc_7 = _loc_6;
            }
            _loc_8 = 1 + _loc_6 / 100 + (_loc_7 - _loc_6) / 100 * _loc_5;
            _loc_9 = 1 + _loc_7 / 100;
            var _loc_10:* = 1 + param1.addPercent;
            var _loc_11:* = EquipBasePropUtil.instance.getStrengthenProps(param2, _loc_8, _loc_9, _loc_10);
            return _loc_11;
        }// end function

        private function getStrengInfo2(param1:ItemData) : Array
        {
            return EquipBasePropUtil.instance.getStrengthenProps2(param1);
        }// end function

        private function updateEquipByType(param1:Object) : void
        {
            if (this._forgingModule && !this._forgingModule.isHide)
            {
                this._forgingModule.updateEquipForgingInfo(param1);
            }
            this.extraOperAfterForging(param1.updateType);
            return;
        }// end function

        private function extraOperAfterForging(param1:int) : void
        {
            var _loc_2:* = this._forgingModule.currSelPage;
            switch(_loc_2)
            {
                case ForgingConst.Page_EquipStrengthen:
                {
                    if (param1 == UpdateCode.EUpdateCodeBagMove)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingEquipReplace));
                    }
                    break;
                }
                case ForgingConst.Page_EquipRefresh:
                {
                    break;
                }
                case ForgingConst.Page_QualityUpgrade:
                {
                    break;
                }
                case ForgingConst.Page_ColorAdvance:
                {
                    break;
                }
                case ForgingConst.Page_GemEmbed:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingGemInfoUpdate));
                    break;
                }
                case ForgingConst.Page_GemStrengthen:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingGemInfoUpdate));
                    break;
                }
                case ForgingConst.Page_EquipTransform:
                {
                    break;
                }
                case ForgingConst.Page_ItemDecompose:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function displayUpValue(param1:Array) : void
        {
            (this._forgingModule.currentPanel as StrengthenPanel).displayUpValue(param1);
            return;
        }// end function

        private function unloadEquipHandler(event:DataEvent) : void
        {
            var _loc_2:ItemData = null;
            var _loc_3:PlayerEquipItem = null;
            var _loc_4:StrengthenPanel = null;
            if (this._forgingModule && this._forgingModule.currentPanel)
            {
                _loc_2 = event.data as ItemData;
                _loc_3 = this._forgingModule.equipDisplaySpr.currSelEquip;
                if (_loc_2 && _loc_3 && _loc_3.itemData)
                {
                    if (_loc_2.itemInfo.type == _loc_3.itemData.itemInfo.type)
                    {
                        _loc_3.setSelEffect(false);
                        this._forgingModule.equipDisplaySpr.currSelEquip = null;
                        this._forgingModule.currentPanel.clearUI();
                        if (!GameController.playerSystem.isViewShow)
                        {
                            GameProxy.equip.dress(null, _loc_2.serverData.uid);
                        }
                        if (this._forgingModule.currentPanel is StrengthenPanel)
                        {
                            _loc_4 = this._forgingModule.currentPanel as StrengthenPanel;
                            if (_loc_4.isPlaying1 || _loc_4.isPlaying2)
                            {
                                _loc_4.stopAllStrengthenEffect();
                            }
                        }
                        if (this._forgingModule.currentPanel is EquipColorAdvancePanel)
                        {
                            (this._forgingModule.currentPanel as EquipColorAdvancePanel).stopAllEffect();
                        }
                    }
                }
            }
            return;
        }// end function

        public function updateCombat() : void
        {
            if (this._forgingModule && this._forgingModule.equipDisplaySpr && !this._forgingModule.equipDisplaySpr.isDisposed)
            {
                this._forgingModule.equipDisplaySpr.updateComBat();
            }
            return;
        }// end function

        public function gemPageHandler(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = this._forgingModule.equipDisplaySpr.currSelEquip;
            if (_loc_2 && _loc_2.itemData)
            {
                _loc_3 = _loc_2.itemData.itemInfo.type;
                this.updateGemInfo(_loc_3);
            }
            else
            {
                this.updateGemInfo(-1);
            }
            return;
        }// end function

        private function backPackItemUpdateHandler(param1:Object) : void
        {
            var _loc_2:ItemData = null;
            var _loc_3:int = 0;
            var _loc_4:PlayerEquipItem = null;
            if (this._forgingModule && this._forgingModule.currentPanel)
            {
                _loc_2 = param1 as ItemData;
                _loc_3 = -1;
                _loc_4 = this._forgingModule.equipDisplaySpr.currSelEquip;
                this._forgingModule.currentPanel.updateConsumeState();
                if (_loc_2 && _loc_2.itemInfo.group == EGroup._EGroupStuff && _loc_2.itemInfo.category == EStuff._EStuffJewel)
                {
                    if (this._forgingModule.currentPanel is GemEmbedPanel)
                    {
                        if (_loc_4 && _loc_4.itemData)
                        {
                            _loc_3 = _loc_4.itemData.itemInfo.type;
                        }
                        this.updateGemInfo(_loc_3);
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ForgingGemInfoUpdate));
                }
            }
            if (!this.isInCountDown())
            {
                if (this._forgingModule == null || this._forgingModule && this._forgingModule.isHide)
                {
                    this.callStrengTip();
                }
            }
            return;
        }// end function

        private function openForgingPanelHandler(event:DataEvent) : void
        {
            this.openForgingPanel(event.data);
            return;
        }// end function

        private function openCompoundPanel(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            CompoundPanel.curItem = _loc_2;
            this.openForgingPanel(ForgingConst.Page_Compound);
            if (_loc_2)
            {
                this._forgingModule.resetCompoundDataProvider();
            }
            return;
        }// end function

        private function openForgingPanel(param1:Object) : void
        {
            var _loc_2:int = 0;
            if (!(param1 is String))
            {
                _loc_2 = param1 is int ? (param1 as int) : (param1.pageIndex as int);
            }
            if (!this.isOpenFuncPanel(_loc_2))
            {
                return;
            }
            if (this.isPanelInOpening(_loc_2))
            {
                if (param1 is String || param1 is int)
                {
                    return;
                }
                if (this.isCurrSelEquip(param1.equipData))
                {
                    return;
                }
            }
            (view as ForgingModule).openForgingPanel(param1);
            return;
        }// end function

        private function isOpenFuncPanel(param1:int) : Boolean
        {
            var _loc_4:String = null;
            var _loc_2:* = cache.role.entityInfo.level;
            var _loc_3:* = GameDefConfig.instance.getForgingPanelOpenLevel(param1);
            switch(param1)
            {
                case ForgingConst.Page_EquipStrengthen:
                {
                    _loc_4 = Language.getString(20392);
                    break;
                }
                case ForgingConst.Page_GemStrengthen:
                {
                    _loc_4 = Language.getString(20393);
                    break;
                }
                case ForgingConst.Page_ItemDecompose:
                {
                    _loc_4 = Language.getString(20394);
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (_loc_2 < _loc_3)
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(20395, _loc_4 + _loc_3));
            }
            return _loc_3 <= _loc_2;
        }// end function

        private function isPanelInOpening(param1:int) : Boolean
        {
            var _loc_2:Class = null;
            if (this._forgingModule)
            {
                _loc_2 = this._forgingModule.getPanelClassByPageIndex(param1);
                if (_loc_2 && this._forgingModule.currentPanel is _loc_2)
                {
                    return true;
                }
            }
            return false;
        }// end function

        private function isCurrSelEquip(param1:ItemData) : Boolean
        {
            var _loc_2:PlayerEquipItem = null;
            if (param1)
            {
                _loc_2 = (view as ForgingModule).equipDisplaySpr.currSelEquip;
                if (_loc_2 && _loc_2.itemData)
                {
                    if (_loc_2.itemData.itemInfo.type == param1.itemInfo.type)
                    {
                        return true;
                    }
                }
            }
            return false;
        }// end function

        private function updateRoleComBat(event:Event) : void
        {
            this.updateCombat();
            return;
        }// end function

        private function enableForgingPanel(param1:Object) : void
        {
            this._forgingModule.enableFuncPanel();
            return;
        }// end function

        private function onMoneyUpdateHandler(param1:Object) : void
        {
            if (this._forgingModule)
            {
                this._forgingModule.updateMoneyState();
            }
            return;
        }// end function

        private function onAutoTransferHandler(event:DataEvent) : void
        {
            var targetEquipData:ItemData;
            var roleEquipData:ItemData;
            var onEnterFrame:Function;
            var data:Object;
            var equip:PlayerEquipItem;
            var currEquip:PlayerEquipItem;
            var e:* = event;
            onEnterFrame = function (event:Event) : void
            {
                if (_forgingModule.isResLoadCompl && !_forgingModule.isHide)
                {
                    Global.stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AddTargetEquip, targetEquipData));
                }
                return;
            }// end function
            ;
            targetEquipData = e.data as ItemData;
            if (targetEquipData)
            {
                roleEquipData = cache.pack.packRolePackCache.getEquipByType(targetEquipData.itemInfo.type);
                if (roleEquipData)
                {
                    data;
                    data["pageIndex"] = ForgingConst.Page_EquipTransform;
                    data["equipData"] = roleEquipData;
                    this.openForgingPanel(data);
                    if (this.isPanelInOpening(ForgingConst.Page_EquipTransform))
                    {
                        equip = this._forgingModule.equipDisplaySpr.getEquipById(roleEquipData.uid);
                        if (equip)
                        {
                            currEquip = (GameController.forging.view as ForgingModule).equipDisplaySpr.currSelEquip;
                            if (currEquip)
                            {
                                currEquip.isSelect = false;
                            }
                            this._forgingModule.equipDisplaySpr.currSelEquip = equip;
                            equip.setSelEffect(true);
                            this._forgingModule.currentPanel.addForgingEquip(equip);
                        }
                    }
                    if (!this._forgingModule.isResLoadCompl)
                    {
                        Global.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
                    }
                    else
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.AddTargetEquip, targetEquipData));
                    }
                }
            }
            return;
        }// end function

        private function onAutoTransferHandler2(event:DataEvent) : void
        {
            return;
        }// end function

        private function onTransferSuccHandler(param1:Object) : void
        {
            if (this._putOnEquip)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Equip, this._putOnEquip));
            }
            return;
        }// end function

        private function callStrengTip() : void
        {
            var _loc_4:Array = null;
            var _loc_5:ItemData = null;
            var _loc_1:* = GameDefConfig.instance.getSystemOpenLevel(3);
            var _loc_2:* = GameDefConfig.instance.getSystemOpenLevel(62);
            var _loc_3:* = cache.role.entityInfo.level;
            if (_loc_3 >= _loc_1 && _loc_3 < _loc_2)
            {
                _loc_4 = cache.pack.packRolePackCache.getAllRoleEquips();
                _loc_5 = cache.pack.packRolePackCache.getBestRecommendEquip();
                if (_loc_5 != null)
                {
                    if (_loc_5 && _loc_5.extInfo.strengthen < ForgingConst.MaxStrengLevel && EquipmentUtil.isEquipCanStrengSucc(_loc_5, false))
                    {
                        StrengthenIcon.instance.data = _loc_5;
                        StrengthenIcon.instance.show();
                    }
                }
            }
            return;
        }// end function

        private function onOperateByTips(event:DataEvent) : void
        {
            this._hasOperedTipData = false;
            var _loc_2:* = event.data as ItemData;
            this._currStrengTipData = _loc_2;
            return;
        }// end function

        public function resetCurrStrengTipData() : void
        {
            var onTimeOver:Function;
            onTimeOver = function () : void
            {
                if (_cdData)
                {
                    _cdData.dispose();
                    Cache.instance.cd.unregisterCDData(CDDataType.publicCD, "strengTip");
                    _cdData = null;
                }
                return;
            }// end function
            ;
            this._currStrengTipData = null;
            if (!this._hasOperedTipData)
            {
                if (this._cdData == null)
                {
                    this._cdData = Cache.instance.cd.registerCDData(CDDataType.publicCD, "strengTip", this._cdData);
                    this._cdData.totalTime = 60 * 1000;
                    this._cdData.beginTime = 0;
                    this._cdData.startCoolDown();
                    this._cdData.addFinishCallback(onTimeOver);
                }
            }
            return;
        }// end function

        private function onStrengthenFailHandler(param1:Object) : void
        {
            if (GuideController.currentGuideItemWin == ModuleType.Build)
            {
                GameController.forging.view.hide();
                GuideController.currentGuideItemWin = null;
            }
            return;
        }// end function

        public function isInCountDown() : Boolean
        {
            if (this._cdData)
            {
                return this._cdData.isCoolDown;
            }
            return false;
        }// end function

        public function get forgingWin() : ForgingModule
        {
            return this._forgingModule;
        }// end function

    }
}
